#!/usr/bin/env python3

import argparse
import os
import sys

try:
    from rosidl_generator_cpp import generate_cpp
except ImportError:
    # modifying sys.path and importing the Python package with the same
    # name as this script does not work on Windows
    rosidl_generator_cpp_root = os.path.dirname(os.path.dirname(__file__))
    rosidl_generator_cpp_module = os.path.join(
        rosidl_generator_cpp_root, 'rosidl_generator_cpp', '__init__.py')
    if not os.path.exists(rosidl_generator_cpp_module):
        raise
    from importlib.machinery import SourceFileLoader

    loader = SourceFileLoader('rosidl_generator_cpp', rosidl_generator_cpp_module)
    rosidl_generator_cpp = loader.load_module()
    generate_cpp = rosidl_generator_cpp.generate_cpp


def main(argv=sys.argv[1:]):
    parser = argparse.ArgumentParser(
        description='Generate the C++ ROS interfaces.',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument(
        '--generator-arguments-file',
        required=True,
        help='The location of the file containing the generator arguments')
    args = parser.parse_args(argv)

    generate_cpp(args.generator_arguments_file)


if __name__ == '__main__':
    sys.exit(main())
